package web.suzy.oj.controller.oj;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.annotation.AnonApi;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.vo.ProblemVO;
import web.suzy.oj.pojo.vo.RandomProblemVO;
import web.suzy.oj.service.oj.ProblemService;

import java.util.List;

/**
 * YangSuzy 软件工作室
 * 类名: ProblemController
 * 描述: 题目信息控制器
 * 功能: 处理题目列表请求，题目内容请求。
 *
 * @author YangSuzy
 * Date: 2022/11/22 22:49
 */
@RestController
@RequestMapping("/api")
public class ProblemController {
    @Autowired
    private ProblemService problemService;

    /**
     * 方法名: getProblemList
     * 描述: 获取题目列表
     *
     * @param limit       每页显示数量
     * @param currentPage 当前页
     * @param keyword     关键字
     * @param tagId       标签ID
     * @param difficulty  难度
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.extension.plugins.pagination.Page < web.suzy.oj.pojo.vo.ProblemVO>>
     * @date 2022/11/22 22:50
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/get-problem-list", method = RequestMethod.GET)
    @AnonApi
    public ResultBean<Page<ProblemVO>> getProblemList(
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "currentPage", required = false) Integer currentPage,
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "tagId", required = false) List<Long> tagId,
            @RequestParam(value = "difficulty", required = false) Integer difficulty) {
        return problemService.getProblemList(limit, currentPage, keyword, tagId, difficulty);
    }

    /**
     * 方法名: getRandomProblem
     * 描述: 随机获取一道题目
     *
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.RandomProblemVO>
     * @date 2022/11/22 22:57
     * @auther YangSuzy
     **/
    @GetMapping("/get-random-problem")
    @AnonApi
    public ResultBean<RandomProblemVO> getRandomProblem() {
        return problemService.getRandomProblem();
    }
}
